package Arrays;

/**
 * 作者:hfj
 * 功能:26.删除有序数组中的重复项
 * 日期: 2025/10/17 21:04
 */
public class RemoveDuplicates2 {
    public static void main(String[] args) {
        int[] nums = {0,0,1,1,1,2,2,3,3,4};
        System.out.println(removeDuplicates(nums));
    }
    public static int removeDuplicates(int[] nums) {
        int n = 0;//指针
        //相邻重复的删除,指针下移
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[n]){
                nums[++n] = nums[i];
            }
        }
        return n+1;//返回最后的数组长度
    }
}
